package com.itheima.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {
    //普通
    @Bean("test_queue")
    public Queue testQueue(){
        return QueueBuilder.durable("test_queue")
                .withArgument("x-message-ttl",10000)
                .withArgument("x-dead-letter-exchange","dlx_exchange")
                .withArgument("x-dead-letter-routing-key","dlx.rkey").build();
    }
    @Bean("test_exchange")
    public Exchange testExchange(){
        return ExchangeBuilder.topicExchange("test_exchange").build();
    }

    @Bean
    public Binding bdTest_E_Q(@Qualifier("test_queue")Queue queue,@Qualifier("test_exchange")Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("test.#").noargs();

    }
    //死信
    @Bean("dlx_queue")
    public Queue dlxQueue(){
        return QueueBuilder.durable("dlx_queue").build();
    }
    @Bean("dlx_exchange")
    public Exchange dlxExchange(){
        return ExchangeBuilder.topicExchange("dlx_exchange").build();
    }
    @Bean
    public Binding bdDlx_E_Q(@Qualifier("dlx_queue")Queue queue,@Qualifier("dlx_exchange")Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("dlx.#").noargs();
    }
}
